import com.demo.Student;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.PushBuilder;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name="ExcelServlet",value = "/ExcelServlet.xlsx")
public class ExcelServlet extends HttpServlet {


    public void doGet(HttpServletRequest request , HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.ms-excel ;charset=utf-8");
        Student studentOne = new Student("95001","李勇","男","20","信息");
        Student studentTwo = new Student("95002","刘晨","女","19","数学");

        PrintWriter out = response.getWriter();

        out.println("学号\t姓名\t性别\t年龄\t专业\t");
        out.println(studentOne.getSno()+"\t"+studentOne.getName()+"\t"+studentOne.getSex()+"\t"+studentOne.getAge()+"\t"+studentOne.getCollage()+"\t");
        out.println(studentTwo.getSno()+"\t"+studentTwo.getName()+"\t"+studentTwo.getSex() + "\t"+studentTwo.getAge() + "\t"+studentTwo.getCollage()+"\t");
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
